import {ActionResult} from "../BTreeActionResult";
import BNodeCondition from "../base/BNodeCondition";
const {ccclass, property} = cc._decorator;
@ccclass
/**
 * 结果翻转
 */
export default class BNodeRandomNum extends BNodeCondition {

    private minNum: number = 0;
    private maxNum: number = 0;
    private value: number = 0;
    private randomNum: number = 0;
    /**
     * 1:大于 2:大于等于 3:等于 4:小于 5:小于等于 6:不等于
     * @type {number}
     */
    private type: number = 0;

    protected onEnter(): void {
        this.type = this.getParameter("type");
        this.minNum = this.getParameter("minNum");
        this.maxNum = this.getParameter("maxNum");
        this.value = this.getParameter("value");

        this.randomNum = this.minNum + cc.random0To1() * (this.maxNum - this.minNum);
    }

    public onExcute(): ActionResult {
        let result: boolean = false;
        switch (this.type) {
            case 1:
                result = this.randomNum > this.value;
                break;
            case 2:
                result = this.randomNum >= this.value;
                break;
            case 2:
                result = this.randomNum >= this.value;
                break;
            case 3:
                result = this.randomNum == this.value;
                break;
            case 4:
                result = this.randomNum < this.value;
                break;
            case 5:
                result = this.randomNum <= this.value;
                break;
            case 6:
                result = this.randomNum != this.value;
                break;
        }
        if (result) {
            return ActionResult.SUCCESS;
        } else {
            return ActionResult.FAILURE;
        }
    }
}
